﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Westwind.RazorHosting;

namespace Jhong.FunMVC.Razor
{
    internal static class EngineFactory
    {

        private static RazorEngine _engine;

        static EngineFactory()
        {
            _engine = new RazorEngine();
            LoadAllAssembly();
        }

        public static RazorEngine Engine { get { return _engine; } }


        private static void LoadAllAssembly()
        {
            var binPath = Path.Combine(View.RootPath, "bin");
            var binInfo = new DirectoryInfo(binPath);
            foreach (var file in binInfo.GetFiles())
            {
                if (false == file.Name.EndsWith(".dll", StringComparison.Ordinal)) continue;
                _engine.AddAssembly(Path.Combine(binPath, file.Name));
            }
        }



    }
}
